import {
  Body,
  Controller,
  Post,
  HttpCode,
  Query,
  Req,
  Get,
  Param,
} from '@nestjs/common';
import { AuthService } from './auth.service';
import { UserDto } from './dto/user.dto';
import { ApiTags } from '@nestjs/swagger';

@ApiTags('用户模块')
@Controller('auth')
export class AuthController {
  constructor(private readonly authService: AuthService) {}

  // 登录注册接口
  @HttpCode(200)
  @Post('/loginAndRegister')
  loginAndRegister(@Body() userDto: UserDto) {
    return this.authService.loginAndRegister(userDto);
  }

  // 修改密码
  @HttpCode(200)
  @Post('/forgetPsd')
  forgetPsd(@Body() userDto: UserDto) {
    return this.authService.forgetPassword(userDto.username, userDto.password);
  }

  // 运营后台登录
  @HttpCode(200)
  @Post('/adminLogin')
  adminLogin(
    @Query('username') username: string,
    @Query('password') password: string,
  ) {
    // 简单处理、默认admin、admin运营账号
    if (!username || !password) {
      return {
        code: 1,
        msg: '参数错误',
      };
    }
    if (username !== password || username !== 'admin') {
      return {
        code: 1,
        msg: '用户名或密码错误',
      };
    }
    return this.authService.adminLogin('100000', password);
  }

  // 用户列表
  @HttpCode(200)
  @Get('/getUserList')
  getUserList(@Query('pageIndex') pageIndex: number) {
    pageIndex = pageIndex ? pageIndex : 0;
    return this.authService.getUserListByPageIndex(pageIndex);
  }

  // 用户年、月、周、日增长
  @HttpCode(200)
  @Get('/userRiseInfo')
  userRiseInfo() {
    return this.authService.getUserRiseInfo();
  }

  // 随机增长图
  @HttpCode(200)
  @Get('/userRandomRiseInfo')
  userRandomRiseInfo() {
    return this.authService.getWeekUserRiseInfo();
  }
}
